﻿using EM.OA.DAL;
using EM.OA.DataModel.DBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EM.OA.BLL
{
    public class DictionaryBLL : BLLBase<EMOA_Dictionary>
    {
        /// <summary>
        /// 根据Ｃode获取字典列表
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public List<EMOA_Dictionary> GetDicList(string code)
        {
            using (var db = new EMOAContext())
            {
                var q = from d in db.EMOA_Dictionary
                        join parent in db.EMOA_Dictionary
                        on d.DictionaryParentID equals parent.DictionaryID
                        where parent.DictionaryCode==code
                        select d;

                return q.ToList();
            }
        }

        /// <summary>
        /// 根据code和值获取名字
        /// </summary>
        /// <param name="code"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public string GetDicName(string code, string value)
        {
            using (var db = new EMOAContext())
            {
                var q = from d in db.EMOA_Dictionary
                        join parent in db.EMOA_Dictionary
                        on d.DictionaryParentID equals parent.DictionaryID
                        where parent.DictionaryCode == code && d.DictionaryCode==value
                        select d.DictionaryName;

                return q.FirstOrDefault();
            }
        }
    }
}
